﻿@model IEnumerable<Content>
@{
    var keyword = ViewContext.HttpContext.Request.Query["keyword"].ToString();
}
@using System.Text.RegularExpressions
<ul class="list-group list-group-flush">
    @if (!Model.Any())
    {
        <li class="list-group-item text-center">
            还没有任何数据！
        </li>
    }
    @foreach (var item in Model)
    {
        <li class="list-group-item">
            <div class="row">
                <div class="col-md-10 col-sm-12">
                    <h4>
                        @if (item.IsAsk)
                        {
                            <span title="问题" class="badge badge-warning">问</span>
                            @if (item.IsLockComment)
                            {
                                <span title="已有最佳答案" class="badge badge-secondary"><i class="fa fa-lock"></i></span>
                            }
                        }
                        else
                        {
                            @if (item.IsVideo)
                            {
                                <span title="多媒体视频" class="badge badge-info">视</span>
                            }

                            @if (item.IsOriginal)
                            {
                                <span title="原创内容" class="badge badge-success">原</span>
                            }

                            @if (!item.IsFree())
                            {
                                <span title="需要学费" class="badge badge-danger">费</span>
                            }
                            @if (item.IsSecret)
                            {
                                <span title="私密帖子" class="badge badge-primary">私</span>
                            }

                        }
                        <a asp-page="/Content/Detail" asp-route-id="@item.Id" target="_blank">
                            @if (!keyword.IsNullOrWhiteSpace())
                            {
                                keyword.Split(' ').ForEach(value =>
                                {
                                    if (!value.IsNullOrWhiteSpace())
                                    {
                                        var matches = Regex.Matches(item.Subject, value, RegexOptions.IgnoreCase);
                                        foreach (Match match in matches)
                                        {
                                            item.Subject = item.Subject.Replace(match.Value, $"<span class='text-danger'>{match.Value}</span>");
                                        }
                                    }
                                });

                            }
                            @Html.Raw(item.Subject)

                            @if (item.IsAsk)
                            {
                                <span class="text-sm" title="悬赏@(item.Cost)个金币">
                                    <span class="fa fa-database text-golden"></span> @item.Cost
                                </span>
                            }
                        </a>
                    </h4>
                    <ul class="list-inline mt-3">
                        @if (item.Category != null)
                        {
                            <li class="list-inline-item">
                        <a asp-page="/Content/Index" asp-route-categoryId="@item.Category.Id" class="text-primary text-sm">                            
                                @item.Category.Name
                        </a>
                            </li>
                        }
                        <li class="list-inline-item text-sm text-muted" title="作者"><a target="_blank" asp-page="/User/Index" asp-route-userId="@item.Author.Id"><img class="circle img-avatar-16" src="@item.Author.AvatarUrl" /> @item.Author.UserName</a></li>
                        <li class="list-inline-item text-sm text-muted d-sm-block d-md-none" title="阅读量"><i class="fa fa-eye"></i> @item.VisitNum</li>
                        <li class="list-inline-item text-sm text-muted" title="评论数"><i class="far fa-comments"></i> @item.CommentCount</li>
                        @if (!item.IsAsk)
                        {
                        <li class="list-inline-item text-sm text-muted" title="点攒数"><i class="far fa-thumbs-up"></i> @item.LikeNum</li>
                        }
                        <li class="list-inline-item text-sm text-muted" title="日期"><i class="far fa-calendar-alt"></i> @item.PostedTime.ToHumanDateTimeString()</li>

                    </ul>
                </div>
                <div class="col-md-2 d-none d-md-block text-center">
                    <h4>阅读量</h4>
                    <span class="badge badge-success text-xl">@item.VisitNum</span>
                </div>
            </div>
        </li>
    }
</ul>